package com.asiainfo.wx.api.apibase.bean;

import com.asiainfo.wx.api.apibase.constants.WxResultEnum;

/**
 * Copyright: Copyright (c) 2019  zteits
 *
 * @ClassName: com.asiainfo.wx.api.apibase.bean
 * @Description:
 * @version: v1.0.0
 * @author: atao
 * @date: 2019-10-29   17:17
 * Modification History:
 * Date         Author          Version      Description
 * ---------------------------------------------------------*
 * 2019-10-29      atao          v1.0.0          创建
 */
public class WxResult<T extends BaseDTO> {

    private String msg;

    private T data;

    private WxResultEnum wxResultEnum;

    public WxResult(T data) {
        this.wxResultEnum = WxResultEnum.SUCCESS;
        this.data = data;
    }

    public WxResult(WxResultEnum wxResultEnum) {

        this.wxResultEnum = wxResultEnum;
    }

    public WxResult(WxResultEnum wxResultEnum, String msg) {
        this.msg = msg;
        this.wxResultEnum = wxResultEnum;
    }

    public String getCode() {
        return wxResultEnum.getCode();
    }

    public String getMsg() {
        if (null == msg || msg.length() == 0) {
            msg = wxResultEnum.getDefaultMsg();
        }

        return msg;
    }

    /**
     * 判断是否成功
     * true 成功
     * false 失败
     *
     * @return
     */
    public Boolean isSuccess() {
        return WxResultEnum.SUCCESS.getCode().equals(wxResultEnum.getCode());
    }

    /**
     * 是否失败
     * true 成功
     * false 失败
     *
     * @return
     */
    public Boolean isFail() {
        return !isSuccess();
    }
}
